/**
 * @file lavas config
 * @author kuerbb(kuerbb@aliyun.com)
 */

'use strict'

const path = require('path')
const BUILD_PATH = path.resolve(__dirname, 'dist')
const isDev = process.env.NODE_ENV === 'development'
const isProd = process.env.NODE_ENV === 'production'
const vuxLoader = require('vux-loader') // for vux

module.exports = {
  build: {
    ssr: true,
    path: BUILD_PATH,
    publicPath: '/',
    ssrCopy: isDev ? [] : [
      {
        src: 'server.prod.js'
      },
      {
        src: 'package.json'
      }
    ],
    /**
         * alias for webpack
         *
         * @type {Object.<string, Object>}
         */
    alias: {
      server: {
        'iscroll/build/iscroll-lite$': path.join(__dirname, 'core/iscroll-ssr.js')
      }
    },
    /**
         * node externals
         *
         * @type {Array.<string|RegExp>}
         */
    nodeExternalsWhitelist: [
      /iscroll/
    ],
    extend (config, {type, env}) {
      if (isDev) {
        config.module.rules.push({
          enforce: 'pre',
          test: /\.(js|vue)$/,
          loader: 'eslint-loader',
          exclude: /(node_modules)/
        })
      }
      if (type === 'base') {
        config = vuxLoader.merge(config, {
          plugins: ['vux-ui']
        })
      }
    }
  },
  router: {
    mode: 'history',
    base: '/',
    pageTransition: {
      type: 'slide',
      transitionClass: 'slide'
    }
  },
  serviceWorker: {
    swSrc: path.join(__dirname, 'core/service-worker.js'),
    swDest: path.join(BUILD_PATH, 'service-worker.js'),
    // swPath: '/custom_path/', // specify custom serveice worker file's path, default is publicPath
    globDirectory: BUILD_PATH,
    globPatterns: [
      '**/*.{html,js,css,eot,svg,ttf,woff}'
    ],
    globIgnores: [
      'sw-register.js',
      '**/*.map'
    ],
    appshellUrl: '/appshell',
    dontCacheBustUrlsMatching: /\.\w{8}\./
  }
}
